<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title th:text="${title}"></title>

    <div th:include="/common/layui"></div>
    <div th:include="/common/jq"></div>

    <!--添加 layui 自己的 css js  支持加载-->
    <link href="/css/houtai/manage_base.css"	rel="stylesheet" />
    <script	src="/js/houtai/manage_base.js"></script>
    <!--添加 layui 自己的 css js  支持加载-->

</head>

<script>
    //定义在外面。可以代码中  使用 table
    var table;
    layui.use([ 'laydate', 'laypage', 'layer','form', 'table', 'carousel',
        'upload', 'element' ], function() {
        table = layui.table;
    });

    var global_ids;
    var global_ids_len;

    var w ;//窗口的宽
    var h ;//窗口的高

    //添加
    function add(){
        w = 600;
        h = 500;
        checkWindow();
        //iframe层
        layer.open({
            type: 2,
            title: '添加',
            shadeClose:false,
            shade: 0.8,
            area: [w+'px', h+'px'],
            content: '/houtai/book/add' //iframe的url
        });
    }

    //打开编辑窗口
    function edit(id){
        w = 600;
        h = 500;
        checkWindow();
        layer.open({
            type: 2,
            title: '修改',
            shadeClose: false,
            shade: 0.8,
            area: [w+'px', h+'px'],
            content: '/houtai/book/edit?id='+id //iframe的url
        });
    }

    //子窗口调用 的  关闭窗口方法
    function closeDlg(msg){
        layer.closeAll();
        layer.msg(msg);
        reload_data();
    }

    //相当前刷新  重新加载
    function reload_data(){
        table.reload('table', {
            where: {
            },page: {curr: 1 //重新从第 1 页开始
            }
        });
    }


    //  delSelected()     5     2,25,6,5
    function del(ids){
        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        $.post('/admin/book/delete',{ids:ids},function(result){
            if(result.success){
                layer.closeAll();
                layer.msg('删除成功');
                reload_data();
            }else{
                layer.closeAll();
                layer.alert('删除失败:'+result.msg);
            }
        },'json');
    }

    function allow(userSubId,record){
            $.post("/admin/bookborrow/update",{borrowId:userSubId,record:record},function(date){
                if(date.success){
                    layer.closeAll();
                    layer.msg(date.msg);
                    reload_data();
                }else{
                    layer.closeAll();//关闭loading
                    layer.msg(date.msg);
                }
            },'json');
    }


</script>

<body style="padding-top: 3px;">

<table class="layui-hide"   id="table" lay-filter="table"></table>
</body>

<script type="text/html" id="table_bar">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-xs" lay-event="allow">通过</a>
        <a class="layui-btn layui-btn-xs" lay-event="refuse">拒绝</a>
    </div>
</script>

<script type="text/html" id="format_user_name">
    {{#  if(d.user!= null){ }}
    {{d.user.trueName}}
    {{#  } else { }}
    {{#  } }}
</script>

<script type="text/html" id="format_book_name">
    {{#  if(d.book!= null){ }}
    {{d.book.name}}
    {{#  } else { }}
    {{#  } }}
</script>

<script type="text/html" id="format_user_num">
    {{#  if(d.user!= null){ }}
    {{d.user.id}}
    {{#  } else { }}
    {{#  } }}
</script>

<script type="text/html" id="format_book_bianhao">
    {{#  if(d.book!= null){ }}
    {{d.book.bianhao}}
    {{#  } else { }}
    {{#  } }}
</script>

<script type="text/html" id="format_type">
    {{#  if(d.type== 1){ }}
    未还
    {{#  } else { }}
    已还
    {{#  } }}
</script>
<script>
    layui.use([ 'laydate', 'laypage', 'layer', 'table', 'carousel',
        'upload', 'element' ], function() {
        var laydate = layui.laydate //日期
            , laypage = layui.laypage //分页
            ,layer = layui.layer //弹层
            , table = layui.table //表格
            , carousel = layui.carousel //轮播
            , upload = layui.upload //上传
            , element = layui.element; //元素操作



        table.render({
            elem: '#table'
            ,url: '/admin/bookborrow/list?record=0'
            ,height: 'full-10'
            ,totalRow: true
            ,cols:  [ [
                {checkbox: true, width:50, fixed: true}
                /*,{field:'userId', title: '读者号', width:80 ,style:'font-size: 12px;',templet: '#format_user_num'}
                ,{field:'userId', title: '借阅人姓名', width:90 ,style:'font-size: 12px;',templet: '#format_user_name'}*/
               /* ,{field:'bookId', title: '图书编号', width:120,  style:'font-size: 12px;',templet: '#format_book_bianhao'}*/
                ,{field:'username', title: '借阅人姓名', width:'15%' ,style:'font-size: 12px;'}
                ,{field:'bookId', title: '图书名称', width:'25%',  style:'font-size: 12px;',templet: '#format_book_name'}

              /*  ,{field:'type', title: '状态', width:120,  style:'font-size: 12px;',templet: '#format_type'}*/

                ,{field:'borrowDateTime', title: '借阅时间', width:'15%',  style:'font-size: 12px;'}
               /* ,{field:'returnDateTime', title: '归还时间', width:180,  style:'font-size: 12px;'}*/

                ,{fixed:'right', width:'15%',title: '操作',  toolbar: '#table_bar'}
            ] ]
            ,id: 'table'
            ,page: true
            ,limits:[10,20,30,50],
            limit:10
        });

        //监听工具条 table_bar
        table.on('tool(table)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'allow') {
                allow(data.id,1);
            }
            if (layEvent === 'refuse') {
                allow(data.id,2);
            }
        });
        //监听工具条 table_bar


        //监听单元格编辑
        table.on('edit(table)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段  orderNo  name
            //layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            table_edit_update(data.id,field,value);
        });




    });
</script>



</html>